package com.keray.web.push.worker.impl;


import com.keray.web.push.ClientData;
import com.keray.web.push.ClientMessageData;
import com.keray.web.push.MessageType;
import com.keray.web.push.worker.AbstractSocketWorker;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

import javax.websocket.Session;
import java.util.List;

/**
 * @author by keray
 * date:2021/7/23 9:53 上午
 */
@Slf4j
@Configuration
public class PushSocketWorker extends AbstractSocketWorker {

    @Override
    public MessageType activeType() {
        return MessageType.push;
    }

    @Override
    public void onOpen(Session session, ClientData data) {
        List<ClientMessageData> notPush = messageDataStore.uidAllNotSend(MessageType.push, data.getService(), data.getUid());
        for (ClientMessageData messageData : notPush) {
            webSocket.asyncSend(messageData, session);
        }
    }

}
